package com.bubblecam.thread;

import android.graphics.Canvas;
import android.view.SurfaceHolder;

import com.bubblecam.view.DisplayPanel;

public class ViewThread extends Thread {
	private DisplayPanel panel;
	private SurfaceHolder holder;
	private boolean mRun = false;
	private long mstartTime;
	private long melapsedTime;
	
	
	public ViewThread(DisplayPanel panel) {
		super();
		this.panel = panel;
		this.holder = panel.getHolder();
	}
    
	public void setRunning(boolean status)
    {
    	mRun = status;
    }

	@Override
	public void run()
	{
		Canvas canvas = null;
		mstartTime = System.currentTimeMillis();
		long startTime = mstartTime;
		while(mRun)
		{
			canvas = holder.lockCanvas();
			if(canvas !=null)
			{
				panel.doDraw(canvas);
				panel.animate(melapsedTime);
				melapsedTime = System.currentTimeMillis()-mstartTime;
				holder.unlockCanvasAndPost(canvas);
			}
			mstartTime = System.currentTimeMillis();
		}
		
	}

}
